      DOUBLE PRECISION FUNCTION COST(V,W)
      COMMON /MSTPRM/ MSGLVL
      COMMON /POINTS/ PHI,CHI,TWOTH,N
      INTEGER N,MSGLVL
      DOUBLE PRECISION PHI(20000),CHI(20000),TWOTH(20000)
      INTEGER V,W
      DOUBLE PRECISION DMIN1,DMAX1,DABS
      DOUBLE PRECISION DISTP,DISTC,DISTT
      DISTP=DMIN1(DABS(PHI(V)-PHI(W)),DABS(DABS(PHI(V)-PHI(W))-360.0E+0)
     $        )
      DISTC=DABS(CHI(V)-CHI(W))
      DISTT=DABS(TWOTH(V)-TWOTH(W))
      COST=DMAX1(DISTP/1.25E+0,DISTC/1.5E+0,DISTT/1.15E+0)
      RETURN
      END